#include "Entity.h"
#include "../../Templates/NewObject.h"
#include "../Component/Component.h"

Entity::Entity(entt::entity handle, GameScene* gameScene) :
	mHandle(handle),
	mGameScene(gameScene)
{

}

entt::entity Entity::GetHandle() const
{
	return mHandle;
}

const Transform& Entity::GetTransform() const
{
	return mTransform;
}

Transform& Entity::GetTransform()
{
	return mTransform;
}

uint64 Entity::GetId() const
{
	return mGameScene->GetRegistry().get<IdComponent>(mHandle).id;
}

const std::string& Entity::GetName()
{
	NameComponent* nameComponent = TryGetComponent<NameComponent>();
	if (nameComponent != nullptr)
	{
		return nameComponent->name;
	}
	static std::string defaultName = "Entity";
	return defaultName;
}

void Entity::ReleaseResource()
{
	DeleteObject<Entity>(this);
}

void Entity::Tick(float deltaTime)
{
	OnTick(deltaTime);
	// Component tick
#if 0
	for (const auto& component : mComponents)
	{
		component->Tick(deltaTime);
	}
#endif
}
